# #创建集合
# s = {1, 2, 3, 4}
#

# ss = set('1234')
# print(type(s))
# print(type(ss))

# #集合的添加和删除
# s.add(6)
# print(s)
# s.pop()
# print(s)
# s.remove(4)
# print(s)


# #创建元组
# tuple1 = ()
# print(tuple1)
# tuple2 = (1, "a", 3, "hello", 2.2)


# #创建集合
# s = {1, 2, 3, 4}
#
# ss = set('1234')
# print(type(s))
# print(type(ss))


# #集合的添加和删除
# s.add(6)
# print(s)
# s.pop()
# print(s)
# s.remove(4)
# print(s)


# #创建元组
# tuple1 = ()
# print(tuple1)

s={1,2,3,4}
ss=set('1234')
print(type(s))
print(type(ss))

s.add(6)
print(s)
s.pop()
print(s)
s.remove(4)
print(s)

tuple1=()
print(tuple1)
tuple2=(1,"a",3,"hello",2.2)
print(tuple2)
tuple3=(1,)
print(tuple3)
print(type(tuple3))

tuple1=tuple('hello,world')
print(tuple1)
list1=['python','java','c++','c']
tuple2=tuple(list1)
print(tuple2)

t1=('h','w','g','c','l')
print(t1[2])
print(t1[-3])
print(t1[1:4])
print(t1[0:3:2])
print(t1[-3:-1])


# 修改元组元素
t1 = (1, 2, 3,)
t2 = ('a', 'b', 'c')
t3 = t1 + t2
print(t3)

t3 = (1, 2, 3, 4, 5, 6)
print(t3)
del t3

# 任务
n = input('姓名：')
t = input('电话：')
e = input('邮箱：')
a = input('地址：')
t1 = ("姓名：", n, "电话:", t, "邮箱:", e, "地址：", a)
print(t1)

# 1.1空列表
l1 = []
print(l1)

# 1.2有元素列表
l2 = [1, 2, "python", "java"]
print(l2)
print(type(l2))


# 2.1空列表
l3 = list()
print(l3)

# 2.2字符串转列表
l4 = list("hello world")
print(l4)

# 2.3元组转列表
t5 = tuple("hello")
print(t5)
l5 = list(t5)
print(l5)


# 2.4将range函数转化成列表
l6 = list(range(5))
print(l6)

l7 = [1, 2, 3, 4, 'p', 'w', 'r']
print(l7[4])
print(l7[-2])

l8 = ['p', 'y', 't', 'h', 'o', 'n']
print(l8[2:5])

# 前三个元素
print(l8[:3])

# 后三个元素
print(l8[3:])

# 正数
print(l8[1::2])

# 负数
print(l8[-3:-1])

# 步长是负数
print(l8[::-1])

l9 = [1, 2, 3, 4, "python", "java", 'c']
for i in l9:
    print(i)

l10 = [10, 56, 34, 2, 56, 44, 7]
l10[2] = 100
print(l10)
l11 = [10, 56, 34, 2, 56, 44, 7]
l11[1:4] = [45, -56, 98]
print(l11)

# append()用于在列表的末尾追加元素
l12 = ['a', 'b', 'c', 'f']
print(l12)
l12.append(['e', 'f'])
print(l12)

# extend()在列表的末尾一次添加多个元素
l13 = ['a', 'b', 'c']
l13.extend('d')
print(l13)


# 列表添加列表
l13.extend(['e', 'f', 'g', 'h'])
print(l13)
l13.extend('world')
print(l13)

l14 = ['python', 'c', 'java']
l14.insert(2, 'go')
print(l14)

# 删除元素
l15 = ['a', 'b', 'c', 'd', 'a']
l15.remove('b')
print(l15)


# 若元素不在列表中，删除会报错
l16 = [10, 2, 4, 6, 8, 'a']
l16.pop(3)
print(l16)


# 删除最后一个元素
l16.pop()
print(l16)

l17 = ['a', 'b', 2, 3, 5, 9]
del l17[4]
print(l17)
del l17[1:3]
print(l17)
l18 = [6, 8, 'a', 0]
l18.clear()
print(l18)

# # 任务
# # 创建两个空列表name_list和phone_list，用于存储联系人姓名和电话；
# # 向列表中添加联系人信息；
# # 输入联系人编号修改信息；
# # 输入联系人编号删除信息；
# # # 使用clear()清空通讯录。name_list=['张三'， ’李四', '王五', ‘maliu'],phone_list=[123, 236, 258, 598]
# name_list = []
# phone_list = []
# while 1:
#     print("菜单：1.添加联系人2.修改联系人3.删除联系人")
#     chioce = input("请输入选择：")

#     # 1.添加联系人，包括姓名，手机号
#     if chioce == "1":
#         name_list.append(input("请输入姓名："))
#         phone_list.append(input("电话："))
#         print(name_list)
#         print(phone_list)


#     # 2.修改信息
#     elif chioce == "2":
#         num = int(input("编号："))
#         if len(name_list) > 0 and num <= len(name_list):
#             name_list[num - 1] = input("修改姓名")
#             phone_list[num - 1] = input("修改电话")
#         else:
#             print("联系人编号有误")


#     # 3.删除信息
#     elif chioce == "3":
#         num = int(input("编号："))
#         if len(name_list) > 0 and num <= len(name_list):
#             name_list.pop(num - 1)
#             phone_list.pop(num - 1)
#     else:
#         print("显示联系人信息")
#         print(name_list)
#         print(phone_list)

# ls1 = [1, 5, 7, 'a', 'a', 'c', 'b', 6, 4, 1]
# print(ls1.index('a'))
# print(ls1.index('a', 4))
# print(ls1.index('c', 3, 7))

ls2 = [1, 3, 5, 7, 'a', 'b', 8, 3, 'b', 2, 5, 5, 7, 1]
print(ls2.count(8))
print(ls2.count(5))
print(ls2.count('f'))

ls3 = ['1', '3', '44', '23', '99', '88', '56', '233']
ls3.sort()
print(ls3)
ls3.sort(reverse=True)
print(ls3)
ls4 = [1, 3, 44, 23, 99, 88, 56, 233]
ls4.sort()
print(ls4)
ls4.sort(reverse=True)
print(ls4)

d1 = {'python': 90, "可视化": 89, "英语": 85}
print(type(d1))
d2 = {(23, 89): "great", 30: [1, 3, 4]}
print(type(d2))
d3 = {}
print(type(d3))
d4 = dict(数学=98, 语文=87, 英语=89)
print(d4)



# 字典元素的访问
# 1，字典名
d5 = {'数学': 95, '英语': 92, '语文': 84}
print(d5['数学'])
# 2，get（）方法来获取指定键对应的值，语法格式：字典名.get（key[，default})
d6 = {'数学': 95, '英语': 92, '语文': 84}
print(d6.get('英语'))
print(d6.get('python'))
print(d6.get('prthon', '改键不存在'))

d7 = {'数学': 95, '英语': 92, '语文': 84, 'python': 99}
d7['可视化'] = 100
print(d7)

d8 = {'数学': 95, '英语': 92, '语文': 84, 'python': 99}
d8['语文'] = 100
print(d8)

# 字典删除键值对
# 1，使用del关键字
d9={'数学':95,'英语':92,'语文':84,'python':99}
del d9['语文']
print(d9)
# 2,使用pop(）方法
d9.pop('数学')
print(d9)